<%-- 
    Document   : Login
    Created on : Feb 20, 2012, 11:09:59 AM
    Author     : Admin
--%>

<%@page import="dao.AccountDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Login</title>
        <%@include file="../Template/Header.jsp" %>
    </head>
    <body>        
        <div id="wrmiddle">
            <%@include file="../Template/Left.jsp" %>

            <div id="wrmiddle2">
                <div style="margin-left: 120px; margin-top: 20px">
                    <form action="#" method="post">
                        <table style="text-align: center">
                            <tr>
                                <td>Username:</td>
                                <td>
                                    <input type="text" name="username"/>
                                </td>
                            </tr>
                            <tr>
                                <td>Password:</td>
                                <td>
                                    <input type="text" name="password" />
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <input type="checkbox" name="ckCheckLogin">
                                    Remember me.
                                    </input>
                                </td>                    
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <input type="submit" name="submit" value="submit"/>
                                </td>                
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <a href="#"> Can't access your account.</a>
                                </td>                
                            </tr>
                        </table>
                    </form>
                </div>   
                <%
                    if (request.getParameter("submit") != null) {
                        AccountDAO adao = new AccountDAO();
                        String username = request.getParameter("username");
                        String password = request.getParameter("password");
                        if (username.equals("") || password.equals("")) {
                            out.println("Invalid username or password");
                            return;
                        }
                        if (!adao.getAccountToCheckLogin(username, password).getUsername().equals("")) {
                            session.setAttribute("user", username);
                            RequestDispatcher rd = getServletContext().getRequestDispatcher("/index.jsp");
                            rd.forward(request, response);
                        } else {
                            out.println("Invalid username or password");
                        }
                    }
                %>      
            </div>

            <%@include file="../Template/Right.jsp" %>
        </div>                        
        <%@include file="../Template/Footer.jsp" %>

    </body>
</html>
